package com.web.web;

import java.util.*;

import com.database.daos.*;
import com.database.objects.*;
import com.load.ctrls.IContributionCtrl;
import com.metrics.objects.*;
import com.opensymphony.xwork2.ActionSupport;
import com.web.message.ErrorMessage;

public class DataAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	private IProjectDao projectDao;

	private IContributionCtrl contributionCtrl;

	private Project project;

	private Map<Type, Map<Status, Double>> versionSummary = new HashMap<Type, Map<Status, Double>>();

	private Map<Type, Map<Status, Double>> trackerSummary = new HashMap<Type, Map<Status, Double>>();

	public void validateIndex() {
		if (project == null || project.getName() == null) {
			addActionError(ErrorMessage.errorRequiredField("Project"));
		}
	}

	public String index() {
		project = projectDao.getByName(project.getName());
		versionSummary = contributionCtrl.findSummariesByProject(project, project.getVersionRepository());
		trackerSummary = contributionCtrl.findSummariesByProject(project, project.getTrackerRepository());
		return SUCCESS;
	}

	public void setProjectDao(IProjectDao projectDao) {
		this.projectDao = projectDao;
	}

	public void setContributionCtrl(IContributionCtrl contributionCtrl) {
		this.contributionCtrl = contributionCtrl;
	}

	public Map<Type, Map<Status, Double>> getVersionSummary() {
		return versionSummary;
	}

	public Map<Type, Map<Status, Double>> getTrackerSummary() {
		return trackerSummary;
	}

	public List<Type> getVersionTypes() {
		return VersionRepository.TYPES;
	}

	public List<Status> getVersionStatus() {
		return VersionRepository.STATUS;
	}

	public List<Type> getTrackerTypes() {
		return TrackerRepository.TYPES;
	}

	public List<Status> getTrackerStatus() {
		return TrackerRepository.STATUS;
	}

	public List<String> getRepositories() {
		return Project.REPOSITORIES;
	}

	public List<Graphic> getGraphics() {
		return Arrays.asList(Graphic.values());
	}

	public List<Time> getTimes() {
		return Arrays.asList(Time.values());
	}

	public List<Developer> getDevelopers() {
		return project.getDevelopers();
	}

	public List<String> getSizeMetrics() {
		return Metric.getSizeMetrics();
	}

	public List<String> getQualityMetrics() {
		return Metric.getQualityMetrics();
	}

	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

}